package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.ProductSpecService;
import com.atguigu.spzx.model.entity.product.ProductSpec;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Tag(name = "商品规格管理")
@RequestMapping("/admin/product/productSpec")
@CrossOrigin(allowCredentials = "true" , originPatterns = "*" , allowedHeaders = "*")
public class ProductSpecController {
    @Autowired
    private ProductSpecService productSpecService;

    @PostMapping("/save")
    @Operation(summary = "保存商品规格")
    public Result save(@RequestBody ProductSpec productSpec){
        productSpecService.save(productSpec);
        return Result.ok(null);
    }

    @Operation(summary = "分页查询")
    @GetMapping("/{page}/{limit}")
    public Result<PageInfo<ProductSpec>> findByPage(@PathVariable("page")Integer page,@PathVariable("limit")Integer limit){
        PageInfo<ProductSpec> pageList=productSpecService.findByPage(page,limit);
        return Result.ok(pageList);
    }

    @Operation(summary = "修改")
    @PutMapping("/updateById")
    public Result updateById(@RequestBody ProductSpec productSpec){
        productSpecService.updateById(productSpec);
        return Result.ok(null);
    }

    @Operation(summary = "删除")
    @DeleteMapping("/deleteById/{id}")
    public Result removeById(@PathVariable Integer id){
        productSpecService.removeById(id);
        return Result.ok(null);
    }

    @Operation(summary = "查询所有")
    @GetMapping("/findAll")
    public Result<List<ProductSpec>> finAll(){
        List<ProductSpec> productSpecList=productSpecService.findAll();
        return Result.ok(productSpecList);
    }
}
